Imports System.IO

Public Class Logging

    Private Shared writer As StreamWriter = Nothing
    Private Shared logFileOpen As Boolean = False

    Public Shared ReadOnly Property LogFileName() As String
        Get
            Return Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "BVLog.txt")
        End Get
    End Property

    Private Shared Sub OpenLogFile()
        If logFileOpen = False Then
            writer = New StreamWriter(Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "BVLog.txt"), False)
            logFileOpen = True
        End If
    End Sub

    Public Shared Sub CloseLogFile()
        If Not writer Is Nothing Then
            writer.Close()
            logFileOpen = False
        End If
    End Sub

    Public Shared Sub Write(ByVal message As String)
        If logFileOpen = False Then
            OpenLogFile()
        End If
        writer.Write(message)
    End Sub

    Public Shared Sub WriteLine(ByVal message As String)
        If logFileOpen = False Then
            OpenLogFile()
        End If
        writer.Write(message & vbNewLine)
    End Sub

End Class
